package cn.ibizlab.odoo.core.odoo_base.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Ibase_partner_merge_automatic_wizard;
import cn.ibizlab.odoo.core.odoo_base.domain.Base_partner_merge_automatic_wizard;
import cn.ibizlab.odoo.core.odoo_base.filter.Base_partner_merge_automatic_wizardSearchContext;
import cn.ibizlab.odoo.core.odoo_base.service.IBase_partner_merge_automatic_wizardService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[合并业务伙伴向导] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Base_partner_merge_automatic_wizardServiceImpl implements IBase_partner_merge_automatic_wizardService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Ibase_partner_merge_automatic_wizardClientService base_partner_merge_automatic_wizardClientService;

    @Override
    public void createBatch(List<Base_partner_merge_automatic_wizard> base_partner_merge_automatic_wizards, int batchSize) {

                        //base_partner_merge_automatic_wizardClientService.createBatch(base_partner_merge_automatic_wizards,batchSize) ;

    }

    @Override
    public boolean update(Base_partner_merge_automatic_wizard base_partner_merge_automatic_wizard) {
        boolean bOk = false ;
        Ibase_partner_merge_automatic_wizard clientModel = this.convert2Model(base_partner_merge_automatic_wizard,null);
        base_partner_merge_automatic_wizardClientService.update(clientModel) ;
        this.convert2Domain(clientModel,base_partner_merge_automatic_wizard) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //base_partner_merge_automatic_wizardClientService.removeBatch(base_partner_merge_automatic_wizards) ;

    }

    @Override
    public void updateBatch(List<Base_partner_merge_automatic_wizard> base_partner_merge_automatic_wizards, int batchSize) {

        //base_partner_merge_automatic_wizardClientService.updateBatch(base_partner_merge_automatic_wizards,batchSize) ;

    }

    @Override
    public boolean create(Base_partner_merge_automatic_wizard base_partner_merge_automatic_wizard) {
        boolean bOk = false ;
        Ibase_partner_merge_automatic_wizard clientModel = this.convert2Model(base_partner_merge_automatic_wizard,null);
        base_partner_merge_automatic_wizardClientService.create(clientModel) ;
        this.convert2Domain(clientModel,base_partner_merge_automatic_wizard);
        bOk = true ;

        return bOk ;
    }

    @Override
    public Base_partner_merge_automatic_wizard get(Integer id) {
        Ibase_partner_merge_automatic_wizard clientModel = base_partner_merge_automatic_wizardClientService.createModel();
        clientModel.setId(id);
        base_partner_merge_automatic_wizardClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Base_partner_merge_automatic_wizard get(Base_partner_merge_automatic_wizard base_partner_merge_automatic_wizard) {
        Base_partner_merge_automatic_wizard retbase_partner_merge_automatic_wizard = this.get(base_partner_merge_automatic_wizard.getId()) ;
    	BeanCopier copier=BeanCopier.create(retbase_partner_merge_automatic_wizard.getClass(), base_partner_merge_automatic_wizard.getClass(), false);
        copier.copy(retbase_partner_merge_automatic_wizard, base_partner_merge_automatic_wizard, null);
        return base_partner_merge_automatic_wizard ;
    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Ibase_partner_merge_automatic_wizard clientModel = base_partner_merge_automatic_wizardClientService.createModel();
        clientModel.setId(id);
        base_partner_merge_automatic_wizardClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Base_partner_merge_automatic_wizard> searchDefault(Base_partner_merge_automatic_wizardSearchContext context) {
        List<Base_partner_merge_automatic_wizard> list = new ArrayList<Base_partner_merge_automatic_wizard>();
        Page<cn.ibizlab.odoo.core.client.model.Ibase_partner_merge_automatic_wizard> clientModelList = base_partner_merge_automatic_wizardClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ibase_partner_merge_automatic_wizard clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Base_partner_merge_automatic_wizard>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据合并合作伙伴明细行查询
     */
    @Override
    public Page<Base_partner_merge_automatic_wizard> selectByOdoo_current_line(Integer id){
        Base_partner_merge_automatic_wizardSearchContext context = new Base_partner_merge_automatic_wizardSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Base_partner_merge_automatic_wizard> list = new ArrayList<Base_partner_merge_automatic_wizard>();
        Page<cn.ibizlab.odoo.core.client.model.Ibase_partner_merge_automatic_wizard> clientModelList = base_partner_merge_automatic_wizardClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ibase_partner_merge_automatic_wizard clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Base_partner_merge_automatic_wizard>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据联系人查询
     */
    @Override
    public Page<Base_partner_merge_automatic_wizard> selectByOdoo_dst_partner(Integer id){
        Base_partner_merge_automatic_wizardSearchContext context = new Base_partner_merge_automatic_wizardSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Base_partner_merge_automatic_wizard> list = new ArrayList<Base_partner_merge_automatic_wizard>();
        Page<cn.ibizlab.odoo.core.client.model.Ibase_partner_merge_automatic_wizard> clientModelList = base_partner_merge_automatic_wizardClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ibase_partner_merge_automatic_wizard clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Base_partner_merge_automatic_wizard>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Base_partner_merge_automatic_wizard> selectByOdoo_create(Integer id){
        Base_partner_merge_automatic_wizardSearchContext context = new Base_partner_merge_automatic_wizardSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Base_partner_merge_automatic_wizard> list = new ArrayList<Base_partner_merge_automatic_wizard>();
        Page<cn.ibizlab.odoo.core.client.model.Ibase_partner_merge_automatic_wizard> clientModelList = base_partner_merge_automatic_wizardClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ibase_partner_merge_automatic_wizard clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Base_partner_merge_automatic_wizard>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Base_partner_merge_automatic_wizard> selectByOdoo_write(Integer id){
        Base_partner_merge_automatic_wizardSearchContext context = new Base_partner_merge_automatic_wizardSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Base_partner_merge_automatic_wizard> list = new ArrayList<Base_partner_merge_automatic_wizard>();
        Page<cn.ibizlab.odoo.core.client.model.Ibase_partner_merge_automatic_wizard> clientModelList = base_partner_merge_automatic_wizardClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ibase_partner_merge_automatic_wizard clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Base_partner_merge_automatic_wizard>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Ibase_partner_merge_automatic_wizard convert2Model(Base_partner_merge_automatic_wizard domain , Ibase_partner_merge_automatic_wizard model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = base_partner_merge_automatic_wizardClientService.createModel() ;
        }

         if(domain.getMaximum_groupDirtyFlag())
            model.setMaximum_group(domain.getMaximum_group());
         if(domain.getGroup_by_parent_idDirtyFlag())
            model.setGroup_by_parent_id(domain.getGroup_by_parent_id());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getNumber_groupDirtyFlag())
            model.setNumber_group(domain.getNumber_group());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getLine_idsDirtyFlag())
            model.setLine_ids(domain.getLine_ids());
         if(domain.getGroup_by_vatDirtyFlag())
            model.setGroup_by_vat(domain.getGroup_by_vat());
         if(domain.getExclude_contactDirtyFlag())
            model.setExclude_contact(domain.getExclude_contact());
         if(domain.getPartner_idsDirtyFlag())
            model.setPartner_ids(domain.getPartner_ids());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getGroup_by_emailDirtyFlag())
            model.setGroup_by_email(domain.getGroup_by_email());
         if(domain.getGroup_by_is_companyDirtyFlag())
            model.setGroup_by_is_company(domain.getGroup_by_is_company());
         if(domain.getStateDirtyFlag())
            model.setState(domain.getState());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getExclude_journal_itemDirtyFlag())
            model.setExclude_journal_item(domain.getExclude_journal_item());
         if(domain.getGroup_by_nameDirtyFlag())
            model.setGroup_by_name(domain.getGroup_by_name());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getDst_partner_id_textDirtyFlag())
            model.setDst_partner_id_text(domain.getDst_partner_id_text());
         if(domain.getDst_partner_idDirtyFlag())
            model.setDst_partner_id(domain.getDst_partner_id());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
         if(domain.getCurrent_line_idDirtyFlag())
            model.setCurrent_line_id(domain.getCurrent_line_id());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
        return model ;
    }

    public Base_partner_merge_automatic_wizard convert2Domain( Ibase_partner_merge_automatic_wizard model ,Base_partner_merge_automatic_wizard domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Base_partner_merge_automatic_wizard();
        }

        if(model.getMaximum_groupDirtyFlag())
            domain.setMaximum_group(model.getMaximum_group());
        if(model.getGroup_by_parent_idDirtyFlag())
            domain.setGroup_by_parent_id(model.getGroup_by_parent_id());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getNumber_groupDirtyFlag())
            domain.setNumber_group(model.getNumber_group());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getLine_idsDirtyFlag())
            domain.setLine_ids(model.getLine_ids());
        if(model.getGroup_by_vatDirtyFlag())
            domain.setGroup_by_vat(model.getGroup_by_vat());
        if(model.getExclude_contactDirtyFlag())
            domain.setExclude_contact(model.getExclude_contact());
        if(model.getPartner_idsDirtyFlag())
            domain.setPartner_ids(model.getPartner_ids());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getGroup_by_emailDirtyFlag())
            domain.setGroup_by_email(model.getGroup_by_email());
        if(model.getGroup_by_is_companyDirtyFlag())
            domain.setGroup_by_is_company(model.getGroup_by_is_company());
        if(model.getStateDirtyFlag())
            domain.setState(model.getState());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getExclude_journal_itemDirtyFlag())
            domain.setExclude_journal_item(model.getExclude_journal_item());
        if(model.getGroup_by_nameDirtyFlag())
            domain.setGroup_by_name(model.getGroup_by_name());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getDst_partner_id_textDirtyFlag())
            domain.setDst_partner_id_text(model.getDst_partner_id_text());
        if(model.getDst_partner_idDirtyFlag())
            domain.setDst_partner_id(model.getDst_partner_id());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        if(model.getCurrent_line_idDirtyFlag())
            domain.setCurrent_line_id(model.getCurrent_line_id());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        return domain ;
    }


}
